package com.ps.controller;

import com.ps.property.PageBean;
import com.ps.property.QuestionVo;
import com.ps.property.ResponseVO;
import com.ps.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/23 9:21
 */
@Api(tags = "问题接口")
@Controller
@Validated
@Slf4j
public class ProvideQuestionController {
    @Autowired
    QuestionService questionService;

    @ApiOperation(value = "新增问题信息接口",notes = "新增问题信息接口")
    @PostMapping("/questionAdd-provide")
    @ResponseBody
    ResponseVO questionAdd(@Valid @RequestBody QuestionVo questionVo) {
        log.info("问题提供者questionVo={}", questionVo);

        return ResponseVO.success(questionService.questionAdd(questionVo));
    }

    @ApiOperation(value = "分页查询问题信息接口",notes = "分页查询问题信息接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "currentPage", value = "当前页数", required = true),@ApiImplicitParam(name = "pageSize", value = "每页行数", required = true)})
    @GetMapping("/questionQuery-provide")
    @ResponseBody
    ResponseVO questionQuery(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        log.info("问题分页查询提供者--当前页={},每页行数={}", currentPage,pageSize);

        return ResponseVO.success(questionService.questionQuery("%",currentPage,pageSize));
    }

    @ApiOperation(value = "查询回答数量大于0的问题数据接口")
    @GetMapping("/questionQueryByReplyAmountBigZero-provide")
    @ResponseBody
    ResponseVO questionQueryByReplyAmountBigZero() {
        return ResponseVO.success(questionService.questionQueryByReplyAmountBigZero());
    }

    @ApiOperation(value = "查询回答数量=0的问题数据接口")
    @GetMapping("/questionQueryByReplyAmountZero-provide")
    @ResponseBody
    ResponseVO questionQueryByReplyAmountZero() {
        return ResponseVO.success(questionService.questionQueryByReplyAmountZero());
    }

    @ApiOperation(value = "根据问题标题分页查询问题信息接口",notes = "根据问题标题分页查询问题信息接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "currentPage", value = "当前页数", required = true),@ApiImplicitParam(name = "pageSize", value = "每页行数", required = true),@ApiImplicitParam(name = "questionTitle", value = "问题标题", required = true)})
    @GetMapping("/questionQueryByTitle-provide")
    @ResponseBody
    ResponseVO questionQueryByTitle(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize, @RequestParam("questionTitle") String questionTitle) {
        log.info("根据问题标题分页查询提供者--当前页={},每页行数={},问题标题={}", currentPage,pageSize,questionTitle);

        return ResponseVO.success(questionService.questionQuery(questionTitle,currentPage,pageSize));
    }

    @ApiOperation(value = "根据问题id修改问题信息接口",notes = "修改问题信息接口，修改问题")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @PostMapping("/questionUpdate-provide")
    @ResponseBody
    ResponseVO questionUpdate(@Valid @RequestBody QuestionVo questionVo) {
        log.info("根据问题id修改问题信息提供者-questionVo={}", questionVo);

        return ResponseVO.success(questionService.questionUpdate(questionVo));
    }

    @ApiOperation(value = "根据问题id查询问题信息接口",notes = "查询问题信息接口，查询问题")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/questionQueryById-provide/{questionId}")
    @ResponseBody
    ResponseVO questionQueryById(@PathVariable int questionId) {
        log.info("根据问题id查询问题信息提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.questionQueryByQuestionId(questionId));
    }

    @ApiOperation(value = "根据问题ID新增问题浏览数接口")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/addBrowseAmount-provide/{questionId}")
    @ResponseBody
    ResponseVO addBrowseAmount(@PathVariable int questionId) {
        log.info("根据问题ID新增问题浏览数信息提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.addBrowseAmount(questionId));
    }

    @ApiOperation(value = "根据问题ID新增问题回复条数接口")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/addReplyArticleNumber-provide/{questionId}")
    @ResponseBody
    ResponseVO addReplyArticleNumber(@PathVariable int questionId) {
        log.info("根据问题ID新增问题回复条数提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.addReplyArticleNumber(questionId));
    }

    @ApiOperation(value = "根据问题ID新增问题回复人数接口")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/addReplyAmount-provide/{questionId}")
    @ResponseBody
    ResponseVO addReplyAmount(@PathVariable int questionId) {
        log.info("根据问题ID新增问题回复人数提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.addReplyAmount(questionId));
    }

    @ApiOperation(value = "根据问题ID新增问题评论条数接口")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/addCommentAmount-provide/{questionId}")
    @ResponseBody
    ResponseVO addCommentAmount(@PathVariable int questionId) {
        log.info("根据问题ID新增问题评论条数提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.addCommentAmount(questionId));
    }

    @ApiOperation(value = "根据问题ID新增问题收藏人数接口")
    @ApiImplicitParam(name = "questionId",value = "问题ID",required = true)
    @GetMapping("/addCollectAmount-provide/{questionId}")
    @ResponseBody
    ResponseVO addCollectAmount(@PathVariable int questionId) {
        log.info("根据问题ID新增问题收藏人数提供者-问题ID={}", questionId);

        return ResponseVO.success(questionService.addCollectAmount(questionId));
    }
}
